//
//  ShareViewController.m
//  OnionHome
//
//  Created by fengjie on 2019/9/18.
//  Copyright © 2019 FengJie. All rights reserved.
//

#import "ShareViewController.h"
#import "ReportArticleToastController.h"
#import "ForwardingController.h"

@interface ShareViewController ()

@end

@implementation ShareViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self createUI];
    self.isHidenNaviBar = YES;
}

-(void)createUI{
    UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect: self.view.bounds byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight cornerRadii:CGSizeMake(15,15)];
    //创建 layer
    CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
    maskLayer.frame = self.view.bounds;
    //赋值
    maskLayer.path = maskPath.CGPath;
    self.view.layer.mask = maskLayer;
    
    UIView * view = [self createTopView];
    UIView * line = UIView.new;
    line.backgroundColor = UIColorFromRGB(0xF0F0F0);
    [self.view addSubview:view];
    [self.view addSubview:line];
    
    [view mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.right.mas_equalTo(0);
        
    }];
    [line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(0);
        make.height.mas_equalTo(1);
        make.top.mas_equalTo(view.mas_bottom).offset(23);
    }];
    
    UIButton * cancleBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [cancleBtn setTitle:@"取消" forState:UIControlStateNormal];
    [cancleBtn setTitleColor:UIColorFromRGB(0x2A2A2A) forState:UIControlStateNormal];
    cancleBtn.titleLabel.font = SYSTEMFONT(15);
    [self.view addSubview:cancleBtn];
    kWeakSelf(weakSelf);
    [cancleBtn addActionHandler:^{
        [weakSelf dismissViewControllerAnimated:YES completion:nil];
    }];
    [cancleBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.bottom.right.mas_equalTo(0);
        make.top.mas_equalTo(line.mas_bottom);
    }];
    
}
-(UIView *)createTopView{
    UIView * view = UIView.new;
    NSArray * array = @[@"微信",@"朋友圈",@"钉钉",@"QQ",@"微博",@"转发",@"收藏",@"不感兴趣",@"复制",@"举报"];
//    CGFloat margin = 28;
    CGFloat margin = 0;
    CGFloat width = (KScreenWidth - (margin * 6))/5;
    
    for (NSInteger i = 0 ; i < array.count; i++) {
        UIImageView * imageView = UIImageView.new;
        imageView.image = IMAGE_NAMED(array[i]);
        imageView.userInteractionEnabled = YES;
        imageView.tag = i;
        [imageView addGestureRecognizer:[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapAction:)]];
//        imageView.backgroundColor = KBlackColor;
//        imageView.layer.cornerRadius = width/2;
        
//        UILabel * label = UILabel.new;
//        label.textColor = UIColorFromRGB(0x363647);
//        label.font = SYSTEMFONT(12);
//        label.textAlignment= NSTextAlignmentCenter;
//        label.text = @"微信";
        
//        [view addSubview:imageView];
//        [view addSubview:label];
        
        UIButton * button = [UIButton buttonWithType:UIButtonTypeCustom];
        [button addTarget:self action:@selector(tapAction:) forControlEvents:UIControlEventTouchUpInside];
        [button setImage:IMAGE_NAMED(array[i]) forState:UIControlStateNormal];
        button.tag = i;
        [view addSubview:button];
        
        CGFloat top = 18;
        CGFloat left = (i+1)*margin + i * width;
        
        if (i >4) {
            top = 102;
            left = (i-4)*margin + (i-5) * width;
        }
        [button mas_makeConstraints:^(MASConstraintMaker *make) {
           make.left.mas_equalTo(left);
           make.top.mas_equalTo(top);
           make.width.mas_equalTo(width);
           make.height.mas_equalTo(60);
           if (i > 4) {
               make.bottom.mas_equalTo(0);
           }
        }];
//        [imageView mas_makeConstraints:^(MASConstraintMaker *make) {
//            make.left.mas_equalTo(left);
//            make.top.mas_equalTo(top);
//            make.width.mas_equalTo(width);
//            make.height.mas_equalTo(60);
//            if (i > 4) {
//                make.bottom.mas_equalTo(0);
//            }
//        }];
        
//        [label mas_makeConstraints:^(MASConstraintMaker *make) {
//            make.centerX.mas_equalTo(imageView);
//            make.top.mas_equalTo(imageView.mas_bottom).offset(5);
//            if (i > 4) {
//                make.bottom.mas_equalTo(0);
//            }
//        }];
    }
    return view;
}
-(void)tapAction:(UIButton *)button{
    
    switch (button.tag) {
        case 0:
            
            break;
        case 1:
            
            break;
        case 2:
            
            break;
        case 3:
            
            break;
        case 4:
            
            break;
        case 5:
            [self forwardingAction];
            break;
        case 6:
            [self collectionAction];
            break;
        case 7:
            
            break;
        case 8:
            
            break;
        case 9:
            [self reportArticleToast];
            break;

        default:
            break;
    }
}

/// 收藏
-(void)collectionAction{
    ShowHubMessage(@"收藏成功");
    [self dismissViewControllerAnimated:YES completion:nil];
}
/**
 分享
 */
-(void)forwardingAction{
    PresentationObject * object = [PresentationObject sharedPresentationObject];
    object.subViewFrame = CGRectMake(0, 0, KScreenWidth, KScreenHeight);
    [object showPresentingViewController:self PresentedViewController:[[BasseNavigationController alloc]initWithRootViewController:[ForwardingController new]]];

//    [self.navigationController presentViewController:[[BasseNavigationController alloc]initWithRootViewController:[ForwardingController new]] animated:YES completion:nil];
}

/**
 举报
 */
-(void)reportArticleToast{
    PresentationObject * object = [PresentationObject sharedPresentationObject];
    object.subViewFrame = CGRectMake(0, 100, KScreenWidth, KScreenHeight-100);
    
    [object showPresentingViewController:self PresentedViewController:[[BasseNavigationController alloc]initWithRootViewController:[ReportArticleToastController new]]];

}
@end
